<template>
  <div>
    <el-dialog
      width="40%"
      :visible.sync="formShow"
      append-to-body
      @close="handleClickDeal('cancel')"
      :modal-append-to-body="false"
      :close-on-click-modal="false"
      title="新增字段"
    >
      <el-form :model="form" label-width="90px" size="small">
        <el-form-item label="字段描述">
          <el-input v-model="form.fieldDesc"></el-input>
        </el-form-item>
        <el-form-item label="字段编码">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="handleClickDeal('cancel')"> 取 消
        </el-button>
        <el-button size="medium" type="primary" @click="handleClickDeal('submit')">
          保 存
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "field-detail",
    props: {
      postDetail: {
        type: Object,
        default: {
          show: false
        }
      }
    },
    data() {
      return {
        formShow: false,
        form: {
          fieldDesc: '',
          code: ''
        }
      }
    },
    methods: {
      // 重置表单
      reset() {
        this.form = {
          fieldDesc: '',
          code: ''
        }
      },
      // 点击事件处理
      handleClickDeal(type) {
        switch (type) {
          case 'submit':
            this.formShow = false;
            break
          case 'cancel':
            this.reset()
            this.formShow = false;
            break
        }
      }
    },
    watch: {
      postDetail(value) {
        console.log('value', value)
        this.formShow = value.show
      }
    }
  }
</script>

<style scoped lang="scss">
  ::v-deep {
    .el-dialog {
      border-radius: 3px;
    }
    .el-dialog__body {
      padding: 30px;
    }
    .el-input {
      width: 80%;
    }

  }
</style>
